package com.adopt.service.Impl;

import com.adopt.mapper.CommentMapper;
import com.adopt.pojo.Comment;
import com.adopt.pojo.Result;
import com.adopt.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zhouyue
 * @Date: 2023/09/12/11:09
 * @Description:
 */
@Service
public class CommentServiceImpl implements CommentService {

    @Autowired

    private CommentMapper commentMapper;


    @Override
    public int addComment(Comment comment) {
        int row = commentMapper.addComment(comment);
        return row;
    }

    @Override
    public Result updateComment(Comment comment) {

        int row=commentMapper.updateComment(comment);

        if(row!=1){
            return new Result(200,"修改失败");
        }
        return new Result(100,"修改成功");
    }



    @Override
    public void updateRelationUser(Integer user_id) {

        commentMapper.updateRelationUser(user_id);
    }

    @Override
    public void updateRelationPet(Integer pet_id) {
        commentMapper.updateRelationPet(pet_id);
    }

    @Override
    public List<Comment> getComments() {
        List<Comment> comments = commentMapper.getComments();
        return comments;
    }

    @Override
    public List<Comment> findByPetId(Integer pet_id) {
        List<Comment> byPetId = commentMapper.findByPetId(pet_id);
        return byPetId;
    }

    @Override
    public List<Comment> findByName(String name) {
        List<Comment> byName = commentMapper.findByName(name);
        return byName;
    }

    @Override
    public Comment findById(Integer id) {
        Comment byId = commentMapper.findById(id);
        return byId;
    }

    @Override
    public void deleteBatch(List<Integer> ids) {

        commentMapper.deleteBatch(ids);
    }

    @Override
    public Result deleteComment(Integer id) {

        int row=commentMapper.deleteComment(id);
        if(row!=1){

            return new Result(200,"异常情况");

        }
        return new Result(100,"删除成功");
    }

    }

